home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / recent / palmlink.lha / PalmLink / examples / PalmTime.c next >
C/C++ Source or Header  |  1998-06-21  |  6KB  |  199 lines

  1. /*********************************************************************
  2. **                                                                  **
  3. **        PalmTime        -- Set Amiga or Pilot system time         **
  4. **                                                                  **
  5. *********************************************************************/
  6. /*
  7. **  Copyright © 1998 Richard Körber  --  All Rights Reserved
  8. **    E-Mail: shred@eratosthenes.starfleet.de
  9. **    URL:    http://shredzone.home.pages.de
  10. **
  11. ***************************************************************/
  12. /*
  13. **  This program is free software; you can redistribute it and/or modify
  14. **  it under the terms of the GNU General Public License as published by
  15. **  the Free Software Foundation; either version 2 of the License, or
  16. **  any later version.
  17. **
  18. **  This program is distributed in the hope that it will be useful,
  19. **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. **  GNU General Public License for more details.
  22. **
  23. **  You should have received a copy of the GNU General Public License
  24. **  along with this program; if not, write to the Free Software
  25. **  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. **
  27. **  The author (Richard Körber) reserves the right to revoke the
  28. **  GNU General Public License whenever he feels that it is necessary,
  29. **  especially when he found out that the licence has been abused,
  30. **  ignored or violated, and without prior notice.
  31. **
  32. **  You must not use this source code to gain profit of any kind!
  33. **
  34. ***************************************************************/
  35. /*
  36. **  Compiles with SAS/C, e.g.
  37. **      sc PalmTime.c NOSTACKCHECK DATA=NEAR STRMER CPU=68060 OPT
  38. */
  39.  
  40. #include <stdio.h>
  41. #include <string.h>
  42. #include <clib/alib_protos.h>
  43. #include <clib/exec_protos.h>
  44. #include <clib/dos_protos.h>
  45. #include <clib/utility_protos.h>
  46. #include <clib/palmlink_protos.h>
  47. #include <pragmas/exec_pragmas.h>
  48. #include <pragmas/dos_pragmas.h>
  49. #include <pragmas/utility_pragmas.h>
  50. #include <pragmas/palmlink_pragmas.h>
  51. #include <exec/memory.h>
  52. #include <dos/dos.h>
  53. #include <dos/dosasl.h>
  54. #include <libraries/palmlink.h>
  55.  
  56.  
  57. #define  VERSIONSTR   "0.2ß"
  58. #define  DATESTR      "21.6.98"
  59. #define  COPYRIGHTSTR "1998"
  60. #define  EMAILSTR     "shred@eratosthenes.starfleet.de"
  61. #define  URLSTR       "http://shredzone.home.pages.de"
  62.  
  63. #define  NORMAL       "\2330m"
  64. #define  BOLD         "\2331m"
  65. #define  ITALIC       "\2333m"
  66. #define  UNDERLINE    "\2334m"
  67.  
  68. #define  MKTAG(a,b,c,d)  ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  69.  
  70. static char ver[] = "$VER: PalmTime " VERSIONSTR " (" DATESTR ") " EMAILSTR;
  71. static char titletxt[] = \
  72.   BOLD "PalmTime " VERSIONSTR " (C) " COPYRIGHTSTR " Richard Körber -- all rights reserved" NORMAL "\n"
  73.   BOLD "  WARNING:" NORMAL " This is an early beta release. If you don't\n"
  74.   "    know what this means, do " BOLD "NOT" NORMAL " use this program!\n\n";
  75. static char helptxt[] = \
  76.   "  " ITALIC "E-Mail: " NORMAL EMAILSTR "\n"
  77.   "  " ITALIC "URL:    " NORMAL URLSTR "\n\n"
  78.   ITALIC "Usage:" NORMAL "\n"
  79.   "  DEVICE/K       Serial device (\"serial.device\")\n"
  80.   "  UNIT/K/N       Serial unit (0)\n"
  81.   "  MAXBAUD/K/N    Maximum baud (28800)\n"
  82.   "\n";
  83.  
  84. struct Parameter
  85. {
  86.   STRPTR device;
  87.   LONG   *unit;
  88.   LONG   *maxbaud;
  89. }
  90. param;
  91.  
  92. static char template[] = "SD=DEVICE/K,SU=UNIT/K/N,SB=MAXBAUD/K/N";
  93.  
  94. extern struct DOSBase *DOSBase;
  95. struct Library *PalmlinkBase;
  96. struct Library *UtilityBase;
  97. APTR socket = NULL;
  98. BOOL ignoreError = FALSE;
  99.  
  100.  
  101.  
  102. /*
  103. ** Open a connection to the Pilot
  104. */
  105. int Connect(void)
  106. {
  107.   LONG error;
  108.  
  109.   if(socket) return(TRUE);
  110.  
  111.   socket = PL_OpenSocketTags
  112.     (
  113.     PLTAG_ErrorPtr      , &error,
  114.     PLTAG_SerialDevice  , (param.device  ? param.device   : (unsigned char *)"serial.device"),
  115.     PLTAG_SerialUnit    , (param.unit    ? *param.unit    : 0),
  116.     PLTAG_SerialMaxRate , (param.maxbaud ? *param.maxbaud : 28800),
  117.     TAG_DONE
  118.     );
  119.  
  120.   if(socket)
  121.   {
  122.     Printf("Please press the HotSync button " ITALIC "now" NORMAL "\n");
  123.     return(PL_Accept(socket,10L));
  124.   }
  125.   else
  126.   {
  127.     Printf("** Socket error %ld\n",error);
  128.   }
  129.   return(FALSE);
  130. }
  131.  
  132. /*
  133. ** Close all databases and disconnect
  134. */
  135. void Disconnect(void)
  136. {
  137.   if(!socket) return;
  138.   DLP_AddSyncLogEntry(socket,"-- AMIGA made it possible --\n");
  139.   DLP_EndOfSync(socket,0);
  140.   PL_CloseSocket(socket);
  141. }
  142.  
  143. /*
  144. ** Show Pilot time
  145. */
  146. void cmd_show(void)
  147. {
  148.   struct DLP_SysTime time;
  149.  
  150.   if(!Connect()) return;
  151.   if(!DLP_OpenConduit(socket)) return;
  152.   if(!DLP_GetSysTime(socket,&time))
  153.   {
  154.     PutStr("** Couldn't get time\n");
  155.     return;
  156.   }
  157.  
  158.   Printf("%02ld.%02ld.%04ld %02ld:%02ld:%02ld\n",time.day,time.month,time.year,time.hour,time.minute,time.second);
  159. }
  160.  
  161. /*
  162. ** MAIN PART
  163. */
  164. int main(void)
  165. {
  166.   struct RDArgs *args;
  167.  
  168.   PutStr(titletxt);
  169.  
  170.   if(args = (struct RDArgs *)ReadArgs(template,(LONG *)¶m,NULL))
  171.   {
  172.     if(UtilityBase = OpenLibrary("utility.library",36L))
  173.     {
  174.       if(PalmlinkBase = OpenLibrary("palmlink.library",0L))
  175.       {
  176.         cmd_show();
  177.  
  178.         if(socket)
  179.         {
  180.           if(!ignoreError && (PL_LastError(socket)!=0))
  181.             Printf("** Socket error code %ld\n",PL_LastError(socket));
  182.           Disconnect();
  183.         }
  184.         CloseLibrary(PalmlinkBase);
  185.       }
  186.       else PutStr("** Couldn't open palmlink.library\n");
  187.       CloseLibrary(UtilityBase);
  188.     }
  189.     else PutStr("** Couldn't open utility.library\n");
  190.  
  191.     FreeArgs(args);
  192.   }
  193.   else PutStr(helptxt);
  194.  
  195.   return(0);
  196. }
  197.  
  198. /********************************************************************/
  199.